﻿@model PageDataVM<List<TeacherWithCourse>>
@{
    ViewData["Title"] = "课程管理";
}
@section Css{
<link rel="stylesheet" href="~/css/assessment.css" asp-append-version="true">
<script src="~/lib/layer/layer.js"></script>
<style>
    .layui-layer-page .layui-layer-content {
        overflow-x: hidden !important;
    }
</style>
}
<div class="content" style="overflow-y:auto;">
    <h2>课程管理</h2>

    <div class="content-table">
        <div class="content-ctl">
            <button id="addCourse" class="btn btn-sm btn-primary">添加</button>
        </div>

        <form class="row g-3" style="padding: 10px; display: none;" id="courseForm">
            <div class="col-12">
                <label for="name" class="form-label">课程名</label>
                <input type="text" name="name" class="form-control" id="name">
            </div>
            <div class="col-12">
                <label for="update" class="form-label">上课时间</label>
                <input type="text" name="update" class="form-control" id="update">
            </div>
            <div class="col-12">
                <label for="credit" class="form-label">学分</label>
                <input type="text" name="credit" class="form-control" id="credit">
            </div>
            <div class="col-12">
                <label for="weeks" class="form-label">上课周数</label>
                <input type="text" name="weeks" class="form-control" id="weeks">
            </div>
            <div class="col-12">
                <label for="extrainfo" class="form-label">介绍</label>
                <textarea rows="3" name="extrainfo" class="form-control" id="extrainfo"></textarea>
            </div>
            <div class="col-12">
                <a id="onAddCourse" class="btn btn-primary">添加</a>
            </div>
        </form>

        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">授课编号</th>
                    <th scope="col">课程名</th>
                    <th scope="col">上课时间</th>
                    <th scope="col">学分</th>
                    <th scope="col">上课周数</th>
                    <th scope="col">介绍</th>
                    <th scope="col">操作</th>
                </tr>
            </thead>
            <tbody>
                @{
                    var index = 1;
                    foreach (var item in Model.Data)
                    {
                        <tr>
                            <td scope="row">@index</td>
                            <td>@item.TcId</td>
                            <td>@item.Course!.Name</td>
                            <td>@item.Course.UpDate</td>
                            <td>@item.Course.Credit</td>
                            <td>@item.Course.Weeks</td>
                            <td>@item.Course.ExtraInfo</td>
                            <td>
                                <a class="btn btn-outline-danger btn-sm" onclick="deleteCourse(@item.TcId)">删除</a>
                            </td>
                        </tr>
                        index++;
                    }
                }
            </tbody>
        </table>
        @await Html.PartialAsync("Pagniation")
        @{
            if (Model.Data.Count < 1)
            {
                @Html.Raw("<label class='text-tip'>没有可选学生</label>")
            }
        }
        <div style="width: 100%; height: 10px;"></div>
    </div>
</div>

@section Scripts{
<script src="~/js/select.js" asp-append-version="true"></script>
<script>
    $(function() {
        $("#addCourse").on("click",function(e) {
            //页面层
            layer.open({
                type: 1,
                title:'添加通知',
                //skin: 'layui-layer-rim', //加上边框
                area:['80%','auto'],
                content: $("#courseForm")
            });
        });

        $("#onAddCourse").on('click',function(e) {
            //页面层
            $.ajax({
                url:"/course/add",
                method:"post",
                data:$("#courseForm").serialize(),
                success:function(res) {
                    if (res.suc) {
                        layer.msg('添加成功', {icon: 1});
                        window.location.reload();
                    }else{
                        layer.msg(res.msg, {icon: 1});
                    }
                }
            });
        });
    });

    function deleteCourse(id) {
        //询问框
        layer.confirm('确定删除？', {
            title:"删除",
            btn: ['确定','取消'] //按钮
        }, function(){
            //页面层
            $.ajax({
                url:"/course/delete?id="+id,
                method:"delete",
                success:function(res) {
                    if (res.suc) {
                        layer.msg('删除成功', {icon: 1});
                        window.location.reload();
                    }else{
                        layer.msg(res.msg, {icon: 1});
                    }
                }
            });
        }, function(){
            //layer.msg('也可以这样', {
            //    time: 20000, //20s后自动关闭
            //    btn: ['明白了', '知道了']
            //});
        });
    }
</script>
}
